<template>
  <div class="nav-header">
    <div class="nav-container">
      <div class="nav-back" @click="goHome">
        <i class="nav-icon">←</i>
        <span>返回首页</span>
      </div>
      <div class="nav-title" v-if="title">{{ title }}</div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router';

// 定义props
defineProps({
  title: {
    type: String,
    default: ''
  }
});

const router = useRouter();

// 返回首页方法
const goHome = () => {
  router.push('/');
};
</script>

<style lang="less" scoped>
.nav-header {
  width: 100%;
  height: 56px;
  background: linear-gradient(135deg, #3f51b5 0%, #5c6bc0 100%);
  color: white;
  position: relative;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.nav-container {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.nav-back {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.nav-back:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.nav-icon {
  margin-right: 6px;
  font-size: 18px;
  font-weight: bold;
}

.nav-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.5px;
}
</style>
